<script setup>
import {onMounted, ref} from 'vue'
import { getGradeOptions,getCurrentStudentGrade } from '../../../api/grade.js'

const grades = ref([
])

const semesterOptions = ref([])

const currentSemester = ref()


const getOptions = async () => {
  const res = await getGradeOptions()
  semesterOptions.value = res.semesterOptions;
}

const getGrades = async () => {
  const listRes = await getCurrentStudentGrade();
  grades.value = listRes;
}


onMounted(() => {
  getOptions()
  getGrades();
})

</script>

<template>
  <div class="grades-container">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>成绩查询</span>
          <el-select v-model="currentSemester" placeholder="选择学期">
            <el-option
              v-for="item in semesterOptions"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </div>
      </template>

      <el-table :data="grades" border style="width: 100%">
        <el-table-column prop="courseName" label="课程名称" width="200"  />
        <el-table-column prop="score" label="成绩" width="200" />
        <el-table-column prop="semester" label="学期" width="200" />
      </el-table>
    </el-card>
  </div>
</template>

<style scoped>
.grades-container {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
